package top.tangyh.lamp.care.controller;

import com.google.gson.Gson;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.tangyh.basic.base.R;
import top.tangyh.lamp.care.mqtt.send.SendMqtt;
import top.tangyh.lamp.care.mqtt.send.dto.Msg;
import top.tangyh.lamp.care.properties.MqttProperties;
import top.tangyh.lamp.common.utils.IcuDateUtils;

import java.time.LocalDateTime;

/**
 * @author: zqb
 * @date: 2024/9/18 08:30
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/test/")
@Tag(name = "mqttx消息通知测试")
public class TestSendMqttController {

    private final MqttProperties mqttProperties;

    @Operation(summary = "测试推送刷新消息提醒")
    @GetMapping("/send/mqtt")
    public R send(Integer type) {

        Msg msg =new Msg();
        msg.setRefresh(1);
        msg.setType(type);
        msg.setSendTime(IcuDateUtils.getGivenZoneTimeStr(LocalDateTime.now()));

        Gson gson = new Gson();
        String content = gson.toJson(msg);

        System.out.println(mqttProperties.getUsername());
        SendMqtt.sendToMQTT(content,mqttProperties.getDefaultTopic(),mqttProperties.getHostUrl(),
                mqttProperties.getClientId(),mqttProperties.getUsername(),mqttProperties.getPassword());

        return R.success();
    }


}
